#pragma once

#include <EGL/egl.h>
#include <GLES2/gl2.h>

// Helper class used to draw a simple texture to the current framebuffer.
// Usage is pretty simple:
//
//   1) Create a TextureDraw instance, passing the current EGLDisplay to it.
//
//   2) Each time you want to draw a texture, call draw(texture, rotation),
//      where |texture| is the name of a GLES 2.x texture object, and
//      |rotation| is an angle in degrees describing the clockwise rotation
//      in the GL y-upwards coordinate space. This function fills the whole
//      framebuffer with texture content.
//
class TextureDraw {
public:
    // Create a new instance.
    TextureDraw(EGLDisplay display);

    // Destructor
    ~TextureDraw();

    // Fill the current framebuffer with the content of |texture|, which must
    // be the name of a GLES 2.x texture object. |rotationDegrees| is a
    // clockwise rotation angle in degrees (clockwise in the GL Y-upwards
    // coordinate space).
    bool draw(GLuint texture, float rotationDegrees);

private:
    EGLDisplay mDisplay;
    GLuint mVertexShader;
    GLuint mFragmentShader;
    GLuint mProgram;
    GLint mPositionSlot;
    GLint mInCoordSlot;
    GLint mTextureSlot;
    GLint mRotationSlot;
    GLuint mVertexBuffer;
    GLuint mIndexBuffer;
};
